package com.share.example.spider.utils;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.HashMap;
import java.util.Map;


public class DriverUtil {
    private static Map<String, WebDriver> map = new HashMap<>();

    public static WebDriver getDriver(String name) {

//        System.setProperty("webdriver.chrome.driver", ConfigConst.path);
//        WebDriver tDriver = new ChromeDriver();
//        return tDriver;


        WebDriver driver = map.get(name);
        if (driver != null) {
            return driver;
        } else {
            synchronized (name) {
                WebDriver dri = map.get(name);
                if (dri != null) {
                    return dri;
                }
                String path = System.getProperty("user.home") + "\\Downloads\\chromedriver_win32\\chromedriver.exe";
                System.setProperty("webdriver.chrome.driver", path);
                WebDriver tDriver = new ChromeDriver();
                map.put(name, tDriver);
                return tDriver;
            }
        }
    }

}
